package com.xiaoshuidi.cloud.module.finance.dal.mysql.finance;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceAccountDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface FinanceAccountMapper extends BaseMapperX<FinanceAccountDO> {
    default FinanceAccountDO selectByCustIdAndCustType(String custId, String custType) {
        return selectOne(new LambdaQueryWrapper<FinanceAccountDO>()
                .eq(FinanceAccountDO::getCustId, custId)
                .eq(FinanceAccountDO::getCustType, custType));
    }

    @Update("update `finance_account` set balance = balance - #{amount} where id = #{id}")
    int deduct(Integer id, BigDecimal amount);

    @Update("update finance_account set cust_id=#{userId},cust_name=#{userName},mobile=#{mobile} where cust_id=#{oldUserId} and cust_type='INDIVIDUAL'")
    void updateMemberUser(@Param("userId") Long userId, @Param("userName") String userName, @Param("mobile") String mobile, @Param("oldUserId") Long oldUserId);
}
